当前位置: 首页>>代码示例>>Java>>正文


Java ConflictException类代码示例

本文整理汇总了Java中com.google.api.server.spi.response.ConflictException的典型用法代码示例。如果您正苦于以下问题:Java ConflictException类的具体用法?Java ConflictException怎么用?Java ConflictException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConflictException类属于com.google.api.server.spi.response包,在下文中一共展示了ConflictException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sayHi

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
     * A simple endpoint method that takes a name and says Hi back
     */
   /* @ApiMethod(name = "sayHi")
    public MyBean sayHi(@Named("name") String name) {
        MyBean response = new MyBean();
        response.setData("Hi, " + name);

        return response;
    }*/

    @ApiMethod(name = "insertUser")
    public Users insertUsers(Users users) throws ConflictException {
//If if is not null, then check if it exists. If yes, throw an Exception
//that it is already present
        if (users.getId() != null) {
            if (findRecord(users.getId()) != null) {
                throw new ConflictException("User id already exists,please login");
            }
        }

        ofy().save().entity(users).now();
        return users;
    }
 
开发者ID:LavanyaGanganna,项目名称:Capstoneproject1,代码行数:25,代码来源:MyEndpoint.java

示例2: testRegistrationFailure_NoSeatsAvailable

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@Test(expected = ConflictException.class)
public void testRegistrationFailure_NoSeatsAvailable() throws Exception {
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    Date startDate = dateFormat.parse("03/25/2014");
    Date endDate = dateFormat.parse("03/26/2014");
    List<String> topics = new ArrayList<>();
    topics.add("Google");
    topics.add("Cloud");
    topics.add("Platform");
    // Create a conference as the remaining seats is zero.
    ConferenceForm conferenceForm = new ConferenceForm(
            NAME, DESCRIPTION, topics, CITY, startDate, endDate, 0);
    Conference conference = conferenceApi.createConference(user, conferenceForm);
    conferenceApi.registerForConference(
            user, conference.getWebsafeKey()).getResult();
}
 
开发者ID:udacity,项目名称:ud859,代码行数:17,代码来源:ConferenceApiTest.java

示例3: testRegistrationFailure_AlreadyRegisteredForTheSameConference

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@Test(expected = ConflictException.class)
public void testRegistrationFailure_AlreadyRegisteredForTheSameConference() throws Exception {
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    Date startDate = dateFormat.parse("03/25/2014");
    Date endDate = dateFormat.parse("03/26/2014");
    List<String> topics = new ArrayList<>();
    topics.add("Google");
    topics.add("Cloud");
    topics.add("Platform");
    ConferenceForm conferenceForm = new ConferenceForm(
            NAME, DESCRIPTION, topics, CITY, startDate, endDate, CAP);
    Conference conference = conferenceApi.createConference(user, conferenceForm);
    // Registration
    Boolean result = conferenceApi.registerForConference(
            user, conference.getWebsafeKey()).getResult();
    conference = conferenceApi.getConference(conference.getWebsafeKey());
    Profile profile = ofy().load().key(Key.create(Profile.class, user.getUserId())).now();
    assertTrue("The first registration should succeed.", result);
    assertEquals(CAP - 1, conference.getSeatsAvailable());
    assertTrue("Profile should have the conferenceId in conferenceIdsToAttend.",
            profile.getConferenceKeysToAttend().contains(conference.getWebsafeKey()));

    // The user has already registered for the conference. This should throw an ForbiddenException.
    conferenceApi.registerForConference(
            user, conference.getWebsafeKey()).getResult();
}
 
开发者ID:udacity,项目名称:ud859,代码行数:27,代码来源:ConferenceApiTest.java

示例4: declineInvitation

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
 * Declines an invitation.
 *
 * @param gameId the game id this invitation is for.
 * @param invitationId the invitation id.
 * @throws NotFoundException if there is no record for this gameId and invitationId.
 * @throws ConflictException if the invitation state has changed and the invitation cannot be
 *         declined.
 */
public void declineInvitation(long gameId, long invitationId)
    throws NotFoundException, ConflictException {
  InvitationEntity invitation = get(gameId, invitationId);

  if (invitation == null) {
    throw new NotFoundException("Invitation record not found.");
  }

  if (!invitation.decline()) {
    throw new ConflictException(
        "Unable to decline the invitation because it has already been accepted "
        + "or is no longer valid.");
  }

  dataStore.put(invitation.getEntity());
  cacheInvitationStatus(gameId, invitationId, InvitationEntity.Status.DECLINED);
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:27,代码来源:InvitationService.java

示例5: cancelInvitation

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
 * Cancels an invitation.
 *
 * @param gameId the game id this invitation is for.
 * @param invitationId the invitation id.
 * @throws NotFoundException if there is no record for this gameId and invitationId.
 * @throws ConflictException if the invitation state has changed and the invitation cannot be
 *         cancelled.
 */
public void cancelInvitation(long gameId, long invitationId)
    throws NotFoundException, ConflictException {
  InvitationEntity invitation = get(gameId, invitationId);

  if (invitation == null) {
    throw new NotFoundException("Invitation record not found.");
  }

  if (!invitation.cancel()) {
    throw new ConflictException(
        "Unable to decline the invitation because it has already been accepted.");
  }

  dataStore.put(invitation.getEntity());
  cacheInvitationStatus(gameId, invitationId, InvitationEntity.Status.CANCELED);
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:26,代码来源:InvitationService.java

示例6: checkUser

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@ApiMethod(
        name = "checkUser",
        path = "checkUser",
        httpMethod = ApiMethod.HttpMethod.POST)
public Users checkUser(@Named ("email") String email) throws ConflictException {
   /* List<Users> lusers=ofy().load().type(Users.class).filter("email","[email protected]").list();
    for(Users users:lusers){
        ofy().delete().type(Users.class).id(users.getId()).now();
    }*/

    return ofy().load().type(Users.class).filter("email",email).first().now();

}
 
开发者ID:LavanyaGanganna,项目名称:Capstoneproject1,代码行数:14,代码来源:UsersEndpoint.java

示例7: TxResult

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
private TxResult(Throwable exception) {
    if (exception instanceof NotFoundException ||
            exception instanceof ForbiddenException ||
            exception instanceof ConflictException) {
        this.exception = exception;
    } else {
        throw new IllegalArgumentException("Exception not supported.");
    }
}
 
开发者ID:udacity,项目名称:ud859,代码行数:10,代码来源:ConferenceApi.java

示例8: getResult

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
private ResultType getResult() throws NotFoundException, ForbiddenException, ConflictException {
    if (exception instanceof NotFoundException) {
        throw (NotFoundException) exception;
    }
    if (exception instanceof ForbiddenException) {
        throw (ForbiddenException) exception;
    }
    if (exception instanceof ConflictException) {
        throw (ConflictException) exception;
    }
    return result;
}
 
开发者ID:udacity,项目名称:ud859,代码行数:13,代码来源:ConferenceApi.java

示例9: unregisterFromConference

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
 * Unregister from the specified Conference.
 *
 * @param user An user who invokes this method, null when the user is not signed in.
 * @param websafeConferenceKey The String representation of the Conference Key to unregister
 *                             from.
 * @return Boolean true when success, otherwise false.
 * @throws UnauthorizedException when the user is not signed in.
 * @throws NotFoundException when there is no Conference with the given conferenceId.
 */
@ApiMethod(
        name = "unregisterFromConference",
        path = "conference/{websafeConferenceKey}/registration",
        httpMethod = HttpMethod.DELETE
)
public WrappedBoolean unregisterFromConference(final User user,
                                        @Named("websafeConferenceKey")
                                        final String websafeConferenceKey)
        throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException {
    // If not signed in, throw a 401 error.
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }
    final String userId = getUserId(user);
    TxResult<Boolean> result = ofy().transact(new Work<TxResult<Boolean>>() {
        @Override
        public TxResult<Boolean> run() {
            Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
            Conference conference = ofy().load().key(conferenceKey).now();
            // 404 when there is no Conference with the given conferenceId.
            if (conference == null) {
                return new TxResult<>(new NotFoundException(
                        "No Conference found with key: " + websafeConferenceKey));
            }
            // Un-registering from the Conference.
            Profile profile = getProfileFromUser(user, userId);
            if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                profile.unregisterFromConference(websafeConferenceKey);
                conference.giveBackSeats(1);
                ofy().save().entities(profile, conference).now();
                return new TxResult<>(true);
            } else {
                return new TxResult<>(false);
            }
        }
    });
    // NotFoundException is actually thrown here.
    return new WrappedBoolean(result.getResult());
}
 
开发者ID:udacity,项目名称:ud859,代码行数:50,代码来源:ConferenceApi.java

示例10: acceptInvitation

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
 * Accepts an invitation.
 *
 * @param gameId the game id this invitation is for.
 * @param invitationId the invitation id.
 * @throws NotFoundException if there is no record for this gameId and invitationId.
 * @throws ConflictException if the invitation state has changed and the invitation cannot be
 *         accepted.
 */
public void acceptInvitation(long gameId, long invitationId)
    throws NotFoundException, ConflictException {
  InvitationEntity invitation = get(gameId, invitationId);

  if (invitation == null) {
    throw new NotFoundException("Invitation record not found.");
  }

  if (!invitation.accept()) {
    throw new ConflictException(
        "Unable to accept the invitation because it has already been declined "
        + "or is no longer valid.");
  }

  Transaction transaction = dataStore.beginTransaction();

  try {
    GamePlayEntity inviteePlayer =
        new GamePlayEntity(invitation.getInviteeKey(), invitation.getParentKey());
    GamePlayEntity senderPlayer =
        new GamePlayEntity(invitation.getSenderKey(), invitation.getParentKey());

    dataStore.put(transaction, senderPlayer.getEntity());
    dataStore.put(transaction, inviteePlayer.getEntity());
    dataStore.put(transaction, invitation.getEntity());

    transaction.commit();

    cacheInvitationStatus(gameId, invitationId, InvitationEntity.Status.ACCEPTED);
  } finally {
    if (transaction.isActive()) {
      transaction.rollback();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:solutions-griddler-sample-backend-java,代码行数:45,代码来源:InvitationService.java

示例11: register

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@ApiMethod(
        httpMethod = "POST",
        path = "register"
        )
public void register(RegisterAttendee command) throws ConflictException, NotFoundException, BadRequestException {
	processCommand(command);
}
 
开发者ID:dannormington,项目名称:appengine-cqrs,代码行数:8,代码来源:AttendeeApi.java

示例12: changeName

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@ApiMethod(
        httpMethod = "POST",
        path = "changename"
        )
public void changeName(ChangeAttendeeName command) throws ConflictException, NotFoundException, BadRequestException  {
    processCommand(command);
}
 
开发者ID:dannormington,项目名称:appengine-cqrs,代码行数:8,代码来源:AttendeeApi.java

示例13: changeEmail

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@ApiMethod(
        httpMethod = "POST",
        path = "changeemail"
        )
public void changeEmail(ChangeAttendeeEmail command) throws ConflictException, NotFoundException, BadRequestException  {
    processCommand(command);
}
 
开发者ID:dannormington,项目名称:appengine-cqrs,代码行数:8,代码来源:AttendeeApi.java

示例14: confirmChangeEmail

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
@ApiMethod(
        httpMethod = "POST",
        path = "confirmchangeemail"
        )
public void confirmChangeEmail(ConfirmChangeEmail command) throws ConflictException, NotFoundException, BadRequestException  {
    processCommand(command);
}
 
开发者ID:dannormington,项目名称:appengine-cqrs,代码行数:8,代码来源:AttendeeApi.java

示例15: unregisterFromConference

import com.google.api.server.spi.response.ConflictException; //导入依赖的package包/类
/**
 * Unregister from the specified Conference.
 *
 * @param user An user who invokes this method, null when the user is not signed in.
 * @param websafeConferenceKey The String representation of the Conference Key to unregister
 *                             from.
 * @return Boolean true when success, otherwise false.
 * @throws UnauthorizedException when the user is not signed in.
 * @throws NotFoundException when there is no Conference with the given conferenceId.
 */
@ApiMethod(
        name = "unregisterFromConference",
        path = "conference/{websafeConferenceKey}/registration",
        httpMethod = HttpMethod.DELETE
)
public WrappedBoolean unregisterFromConference(final User user,
                                        @Named("websafeConferenceKey")
                                        final String websafeConferenceKey)
        throws UnauthorizedException, NotFoundException, ForbiddenException, ConflictException {
    // If not signed in, throw a 401 error.
    if (user == null) {
        throw new UnauthorizedException("Authorization required");
    }

    WrappedBoolean result = ofy().transact(new Work<WrappedBoolean>() {
        @Override
        public WrappedBoolean run() {
            Key<Conference> conferenceKey = Key.create(websafeConferenceKey);
            Conference conference = ofy().load().key(conferenceKey).now();
            // 404 when there is no Conference with the given conferenceId.
            if (conference == null) {
                return new  WrappedBoolean(false,
                        "No Conference found with key: " + websafeConferenceKey);
            }

            // Un-registering from the Conference.
            Profile profile = getProfileFromUser(user);
            if (profile.getConferenceKeysToAttend().contains(websafeConferenceKey)) {
                profile.unregisterFromConference(websafeConferenceKey);
                conference.giveBackSeats(1);
                ofy().save().entities(profile, conference).now();
                return new WrappedBoolean(true);
            } else {
                return new WrappedBoolean(false, "You are not registered for this conference");
            }
        }
    });
    // if result is false
    if (!result.getResult()) {
        if (result.getReason().contains("No Conference found with key")) {
            throw new NotFoundException (result.getReason());
        }
        else {
            throw new ForbiddenException(result.getReason());
        }
    }
    // NotFoundException is actually thrown here.
    return new WrappedBoolean(result.getResult());
}
 
开发者ID:udacity,项目名称:ud859,代码行数:60,代码来源:ConferenceApi.java


注:本文中的com.google.api.server.spi.response.ConflictException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。