📄 facadeimpl.java
字号:
}
public void logout() throws RaplaException {
if (this.workingUser == null || this.originalUser!= null)
return;
getLogger().debug("User " + this.workingUser + "loged out.");
this.workingUser = null;
// we need to remove the storage update listener, because the disconnect
// would trigger a restart otherwist
operator.removeStorageUpdateListener( this );
operator.disconnect();
// now we can add it again
operator.addStorageUpdateListener( this );
Runtime.getRuntime().gc();
}
public void changePassword(User user,char[] oldPassword,char[] newPassword) throws RaplaException {
synchronized (operator.getLock()) {
operator.changePassword(user, oldPassword, newPassword);
}
}
/******************************
* Modification-module *
******************************/
public RaplaMap newRaplaMap(Map map) {
return new RaplaMapImpl( map );
}
public RaplaMap newRaplaMap(Collection col) {
return new RaplaMapImpl( col);
}
public CalendarModelConfiguration newRaplaCalendarModel(RaplaMap selected , ClassificationFilter[] filter, String title, Date startDate, Date endDate, Date selectedDate,String view, RaplaMap optionMap) {
return new CalendarModelConfigurationImpl( selected, filter, title, startDate, endDate, selectedDate, view,optionMap);
}
public Reservation newReservation() throws RaplaException
{
Date today = today();
ReservationImpl reservation = new ReservationImpl(today ,today );
Classification classification = getDynamicTypes(DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION)[0].newClassification();
reservation.setClassification(classification);
setNew(reservation);
return reservation;
}
public Appointment newAppointment(Date startDate,Date endDate) throws RaplaException
{
AppointmentImpl appointment = new AppointmentImpl(startDate,endDate);
setNew(appointment);
return appointment;
}
public Allocatable newResource() throws RaplaException
{
return newAllocatable( false );
}
public Allocatable newPerson() throws RaplaException
{
return newAllocatable( true );
}
private Allocatable newAllocatable( boolean isPerson ) throws RaplaException {
AllocatableImpl allocatable = new AllocatableImpl();
allocatable.setPerson( isPerson );
String classificationType = isPerson ? DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION : DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION;
Classification classification = getDynamicTypes( classificationType )[0].newClassification();
User user = getUser();
allocatable.addPermission( allocatable.newPermission() );
if ( !user.isAdmin() ) {
Permission permission = allocatable.newPermission();
permission.setUser( user );
permission.setAccessLevel( Permission.ADMIN );
allocatable.addPermission( permission );
}
allocatable.setClassification(classification);
setNew(allocatable);
return allocatable;
}
public Period newPeriod() throws RaplaException
{
PeriodImpl period = new PeriodImpl();
Date today = today();
period.setStart(DateTools.cutDate(today));
period.setEnd(DateTools.fillDate(today));
setNew(period);
return period;
}
public Date today() {
return operator.today();
}
public Category newCategory() throws RaplaException
{
CategoryImpl category = new CategoryImpl();
setNew(category);
return category;
}
private Attribute createStringAttribute(String key, String name) throws RaplaException {
Attribute attribute = newAttribute(AttributeType.STRING);
attribute.setKey(key);
attribute.getName().setName(i18n.getLang(), i18n.getString(name));
return attribute;
}
public DynamicType newDynamicType(String classificationType) throws RaplaException {
DynamicTypeImpl dynamicType = new DynamicTypeImpl();
dynamicType.setAnnotation("classification-type", classificationType );
dynamicType.setElementKey(createDynamicTypeKey(classificationType));
setNew(dynamicType);
if (classificationType.equals (DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION))
{
dynamicType.addAttribute(createStringAttribute("name","name"));
dynamicType.setAnnotation("nameformat", "{name}");
}
else if (classificationType.equals (DynamicTypeAnnotations.VALUE_RESERVATION_CLASSIFICATION))
{
dynamicType.addAttribute(createStringAttribute("title","reservation.name"));
dynamicType.setAnnotation("nameformat", "{title}");
}
else if (classificationType.equals (DynamicTypeAnnotations.VALUE_PERSON_CLASSIFICATION))
{
dynamicType.addAttribute(createStringAttribute("surname","surname"));
dynamicType.addAttribute(createStringAttribute("forename","forename"));
dynamicType.setAnnotation("nameformat", "{surname} {forename}");
}
return dynamicType;
}
public Attribute newAttribute (AttributeType attributeType) throws RaplaException {
AttributeImpl attribute = new AttributeImpl(attributeType);
setNew(attribute);
return attribute;
}
public User newUser() throws RaplaException {
UserImpl user = new UserImpl();
setNew(user);
Category modifyPreferences = getUserGroupsCategory().getCategory(Permission.GROUP_MODIFY_PREFERENCES_KEY);
if ( modifyPreferences != null)
{
user.addGroup( modifyPreferences);
}
Category readOthers = getUserGroupsCategory().getCategory(Permission.GROUP_CAN_READ_EVENTS_FROM_OTHERS);
if ( readOthers != null)
{
user.addGroup( readOthers);
}
return user;
}
private String createDynamicTypeKey(String classificationType) throws RaplaException {
DynamicType[] dts = getDynamicTypes(classificationType);
int max = 1;
for (int i=0;i<dts.length;i++) {
String key = dts[i].getElementKey();
int len = classificationType.length();
if (key.indexOf(classificationType)>=0
&& key.length() > len
&& Character.isDigit(key.charAt(len))
)
{
try {
int value = Integer.valueOf(key.substring(len)).intValue();
if (value >= max)
max = value + 1;
} catch (NumberFormatException ex) {
}
}
}
return classificationType + (max);
}
private void setNew(RefEntity entity) throws RaplaException {
setNew( entity, null);
}
/** recursivly set new ids */
private void setNew(RefEntity entity, User user) throws RaplaException {
if ( entity.getSubEntities().hasNext() )
{
throw new RaplaException("The current Rapla Version doesnt support cloning entities with sub-entities. (Except reservations)");
}
RaplaType raplaType = ((RaplaObject) entity).getRaplaType();
synchronized (operator.getLock())
{
entity.setId(operator.createIdentifier(raplaType));
}
entity.setVersion(0);
if (getLogger() != null && getLogger().isDebugEnabled())
{
getLogger().debug("new " + entity.getId());
}
if (entity instanceof Ownable)
{
if ( user == null)
user = getUser();
((Ownable)entity).setOwner(user);
}
}
public void checkReservation(Reservation reservation) throws RaplaException {
if (reservation.getAppointments().length == 0)
{
throw new RaplaException(i18n.getString("error.no_appointment"));
}
if (reservation.getName(i18n.getLocale()).trim().length() ==0)
{
throw new RaplaException(i18n.getString("error.no_reservation_name"));
}
}
public Entity edit(Entity obj) throws RaplaException {
if ( obj == null)
throw new NullPointerException("Can't edit null objects");
synchronized (operator.getLock()) {
return operator.editObject( obj, workingUser );
}
}
public Entity clone(Entity obj) throws RaplaException {
if ( obj == null)
throw new NullPointerException("Can't clone null objects");
if ( obj instanceof Reservation)
{
return cloneReservation( (Reservation) obj );
}
try
{
RefEntity clone = (RefEntity) ((Mementable) obj).deepClone();
removeParents( clone );
setNew(clone, this.workingUser);
return clone;
}
catch (ClassCastException ex)
{
throw new RaplaException("This entity can't be cloned ",ex);
}
}
private void removeParents( RefEntity clone )
{
if ( clone instanceof AppointmentImpl )
{
( (AppointmentImpl) clone ).removeParent();
}
if ( clone instanceof CategoryImpl )
{
( (CategoryImpl) clone ).removeParent();
}
}
private Reservation cloneReservation( Reservation obj ) throws RaplaException
{
Reservation clone =(Reservation) ((Mementable) obj).deepClone();
HashMap restrictions = new HashMap();
Allocatable[] allocatables = clone.getAllocatables();
for ( int i=0;i< allocatables.length;i++)
{
restrictions.put( allocatables, clone.getRestriction( allocatables[i]));
}
Appointment[] clonedAppointments = clone.getAppointments();
for ( int i=0;i< clonedAppointments.length;i++)
{
setNew((RefEntity)clonedAppointments[i], this.workingUser);
clone.removeAppointment( clonedAppointments[i] );
}
setNew((RefEntity)clone, this.workingUser);
for ( int i=0;i< clonedAppointments.length;i++)
{
clone.addAppointment( clonedAppointments[i] );
}
for ( int i=0;i< allocatables.length;i++)
{
Appointment[] appointments = (Appointment[])restrictions.get( allocatables[i] );
if ( appointments != null )
{
clone.setRestriction( allocatables[i], appointments );
}
}
return clone;
}
public Entity getPersistant(Entity obj) throws RaplaException {
synchronized (operator.getLock()) {
return operator.getPersistant( obj );
}
}
public void store(Entity obj) throws RaplaException {
if ( obj == null)
throw new NullPointerException("Can't store null objects");
storeObjects(new Entity[] {obj});
}
public void remove(Entity obj) throws RaplaException {
if ( obj == null)
throw new NullPointerException("Can't remove null objects");
removeObjects(new Entity[] {obj});
}
public void storeObjects(Entity[] obj) throws RaplaException {
storeAndRemove( obj, Entity.ENTITY_ARRAY );
}
public void removeObjects(Entity[] obj) throws RaplaException {
storeAndRemove( Entity.ENTITY_ARRAY , obj);
}
public void storeAndRemove(Entity[] obj, Entity[] removedObjects) throws RaplaException {
if (obj.length == 0 && removedObjects.length == 0)
return;
long time = System.currentTimeMillis();
for (int i=0;i< obj.length;i++) {
if ( obj[i] == null)
{
throw new RaplaException("Stored Objects cant be null");
}
if ( obj[i].getRaplaType().equals( Reservation.TYPE ) )
{
checkReservation( (Reservation) obj[i] );
}
}
for (int i=0;i< removedObjects.length;i++) {
if ( removedObjects[i] == null)
{
throw new RaplaException("Removed Objects cant be null");
}
}
synchronized (operator.getLock()) {
operator.storeAndRemove( obj , removedObjects, workingUser);
}
if (getLogger().isDebugEnabled())
getLogger().debug("Storing took " + (System.currentTimeMillis()- time) + " ms.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -